package com.hns.can.mainte.web;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.domain.GridPage;
import com.hns.can.common.service.CommonInitParamService;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.common.web.BaseController;
import com.hns.can.mainte.entity.CommCapacityStatInfoEntity;
import com.hns.can.mainte.service.CapacitorStatusService;
import com.hns.frame.mybatis.Pagination;
import com.hns.tool.export.ExportUtil;
import com.hns.tool.pub.DateTool;

/**
 * 电容状态Controller
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/capacitorStatus")
public class CapacitorStatusController extends BaseController{
	
	final private String[] headerNames = new String[]{"车牌号","运营线路","所属机构","采集时间","电容内部电压","电容SOE","超级电容电压","超级电容电流"};
	final private String[] headerFields = new String[]{"licPltNo", "lineName", "organName", "rcrdTime", "capacityInVtg","soe","capacityInVtg","capacityInEltCrt"};


	@Autowired
	private CapacitorStatusService capacitorStatusService;
	@Autowired
    private CommonInitParamService commonInitParamService;
    
    /**
     * 分页查询电容状态
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
	@RequestMapping("/searchCapacitorStatus")
	@ResponseBody
	public Object searchCapacitorStatus(CommonParamsVo params) throws Exception {
		SysUserEntity user = this.getCurrentUser().getUser();
		commonInitParamService.initParamsLimitCar(params,user,Arrays.asList("T_COMM_CAPACITY_STAT_INFO"));
		Pagination page = capacitorStatusService.searchCapacitorStatus(params);
		GridPage grid = new GridPage(page);
		return this.getReturnResult(grid);
	}
	
	/**
	 * 导出电容状态Excel文件
	 * @param params
	 * @throws Exception
	 * @author:zhangzq
	 * @email:
	 */
	@RequestMapping("/exportCapacitorStatusExcel")
	public void exportCapacitorStatusExcel(CommonParamsVo params,HttpServletResponse response) throws Exception {
		List<CommCapacityStatInfoEntity> list = getCapacitorStatusData(params);
		ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "excel", "CapacitorStatus"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "电容状态数据");
	}
	
	/**
	 * 导出电容状态Pdf文件
	 * @param params
	 * @throws Exception
	 * @author:zhangzq
	 * @email:
	 */
	@RequestMapping("/exportCapacitorStatusPdf")
	public void exportCapacitorStatusPdf(CommonParamsVo params,HttpServletResponse response) throws Exception {
		List<CommCapacityStatInfoEntity> list = getCapacitorStatusData(params);
		ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "pdf", "CapacitorStatus"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "电容状态数据");
		}
	
	/**
	 * 获取电容状态数据
	 * @param params
	 * @return
	 * @throws Exception
	 * @author:zhangzq
	 * @email:
	 */
	private List<CommCapacityStatInfoEntity> getCapacitorStatusData(CommonParamsVo params) throws Exception{
		SysUserEntity user = this.getCurrentUser().getUser();
		commonInitParamService.initParamsLimitCar(params, user, Arrays.asList("T_COMM_CAPACITY_STAT_INFO"));
		List<CommCapacityStatInfoEntity> list = capacitorStatusService.getCapacitorStatusData(params);
		return list;
	}
	
}

